import axios from "axios";
import {swal} from 'vue-swal'
axios.defaults.timeout =  5000;
axios.interceptors.response.use(res => {
    if(!res.data){  //没有任何数据
        swal('服务器没有响应','派智知识管家','error')
        return  
    }
    if(res.data.code!=0){
        swal(res.data.msg || '业务数据异常','派智知识管家','error')
        return
    }
    return res.data
},() => swal('网络通讯失败，请刷新再试','派智知识管家','error')
)


const cal_case_money=function(data){  
    return axios.post('/api/pub/cal_case_money',data)
}
const craw_query=function(data){  
    return axios.post('/api/pub/craw_query',data)
}
const official_reg=function(data){  
    return axios.post('/api/client/official_reg',data)
}
const sendSMS=function(data){  //发送短信 reg,forget_pwd
    data.type='雇主端'
    return axios.post('/api/pub/send_sms',data);
}
const userinfo=function(client_id,unique_code){  
    return axios.get('/api/client/userinfo?openid='+unique_code+'&client_id='+client_id+'&activity_id=1')
}
const activity_rank=function(data){  
    return axios.post('/api/client/activity_rank',data)
}
const activity_login=function(data){  
    return axios.post('/api/client/activity_login',data)
}
const login=function(data){  
    return axios.post('/api/client/login',data)
}
const reset_pwd=function(data){  
    return axios.post('/api/client/reset_pwd',data)
}
const inc_share_coupons=function(){  
    let formdata=new FormData()
    formdata.append("client_id",localStorage.getItem('client_id'))
    formdata.append("openid",localStorage.getItem('unique_code'))
    formdata.append("activity_id",1)
    return axios.post('/api/client/inc_share_coupons',formdata,{headers: {'Content-Type': 'application/x-www-form-urlencoded'}})
}
const invite_history=function(){ 
    let formdata=new FormData()
    formdata.append("client_id",localStorage.getItem('client_id'))
    formdata.append("openid",localStorage.getItem('unique_code'))
    return axios.post('/api/client/invite_history',formdata,{headers: {'Content-Type': 'application/x-www-form-urlencoded'}})
}
const jssdk=function(data){  
    return axios.post('/api/pub/jssdk',data)
}
const add_msg=function(data){  
    return axios.post('/api/pub/add_msg',data)
}
const trademark=function(data){  
    return axios.post('/api/trademark/index',data)
}
const trademark_detail=function(data){  
    return axios.post('/api/trademark/detail',data)
}
const trademark_search=function(data){  
    return axios.post('/api/trademark/search',data)
}

export  {
    cal_case_money,
    craw_query,
    official_reg,
    sendSMS,
    userinfo,
    activity_rank,
    activity_login,
    inc_share_coupons,
    invite_history,
    jssdk,
    reset_pwd,
    login,
    add_msg,
    trademark,
    trademark_detail,
    trademark_search
}